#include <iostream>
#include <string>

using namespace std;



void copyString(char *input, int offset, int length, bool invert, char *output, int output_offset)
{
	char * strCopyInPut = new char;
	char * strCopyOutPut = new char;

	int dodaiOutPut = strlen(output);
	int dodaiInPut = strlen(input);

	int j = 0;
	for (int i = offset; i < dodaiInPut; i++)
	{
		strCopyInPut[j++] = input[i];
	}

	if (invert == true)
	{
		for (int i = 0; i < length; i++)
		{
			for (int j = 1; j < length; j++)
			{
				if (i < j)
				{
					char tamp = strCopyInPut[i];
					strCopyInPut[i] = strCopyInPut[j];
					strCopyInPut[j] = tamp;
				}
			}
		}

		int j = 0;
		for (int i = 0; i < dodaiOutPut; i++)
		{
			if (i >= output_offset && output[i] !='\0')
			{
				output[i] = strCopyInPut[j++];
			}
		}
	}
	else
	{
		int j = 0;
		for (int i = 0; i < dodaiOutPut; i++)
		{
			if (i >= output_offset && output[i] !='\0')
			{
				output[i] = strCopyInPut[j++];
			}

		}
	}



}

int main()
{
	//           012345678910
	char st[] = "Hello world";
	//           0123456789101112131415
	char st2[] = "My name is C++";
	//copyString(st, 6, 5, true, st2, 11);
	copyString(st, 6, 5, true, st2, 11);
	cout<<st2<<endl;
	system("pause");
}